<%--
  Created by IntelliJ IDEA.
  User: zhuya
  Date: 2016/1/28
  Time: 16:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="privilege" uri="/WEB-INF/privilege.tld" %>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <title>用户登录</title>
    <link rel="stylesheet" href="<c:url value='/resource/wechat/css/frozen.css'/>">
    <link rel="stylesheet" type="text/css" href="<c:url value='/resource/wechat/css/main.css'/>"/>
    <script src="<c:url value='/resource/js/jquery-2.0.min.js'/>"></script>
    <script src="<c:url value='/resource/js/jquery.form.min.js'/>"></script>
    <script src="<c:url value='/resource/wechat/js/zepto.min.js'/>"></script>
    <script src="<c:url value='/resource/wechat/js/frozen.js'/>"></script>


</head>
<body ontouchstart>
<section class="ui-container">
    <section id="tab">
        <div class="demo-item">
            <div class="demo-block">
                <div class="ui-tab">

                    <ul class="ui-tab-content" style="width:100%">
                        <li>
                            <div class="ui-form-item ui-form-item-show ui-border-b"
                                 style="border-top: 1px solid #E2E2E2;">
                                <label for="#">手机号码：</label>
                                <input class="text14" type="text" id="loginId" onkeypress="onlyNumber()" maxlength="11" value=""/>
                            </div>
                            <div class="ui-form-item ui-form-item-show ui-border-b">
                                <label for="#"><span class="text_white">密码</span>密码：</label>

                                <input type="password" value="" id="password" maxlength="20">
                            </div>
                            <div class="ui-form" style="margin-top: 10px;">
                                <form action="#">
                                    <div class="ui-form-item ui-form-item-switch" style="position: relative;">

                                        <%--<label class="ui-switch" style="left: 15px;">
                                            <input type="checkbox" checked="checked">
                                        </label>--%>

                                        <%--<p class="text_grey3" style="position: absolute;left: 75px;">下次自动登入</p>--%>
                                        <a href="<c:url value='/weixin/wx_member/fp?gowhere=${gowhere}&openId=${openId}'/>"
                                           style="position: absolute; right: 10px;">忘记密码？</a>
                                    </div>

                                </form>
                            </div>
                            <div class="ui-btn-wrap">
                                <button class="ui-btn-lg ui-btn-primary" id="gsubmitbtn">
                                    登录
                                </button>
                            </div>
                            <div class="ui-btn-wrap">
                                <button class="ui-btn-lg ui-btn-primary" id="register">
                                        注册
                                </button>
                            </div>
                            <input type="hidden" id="openId" value="${openId}">
                        </li>

                    </ul>
                </div>
            </div>
            <script class="demo-script">
            </script>
        </div>
    </section>
</section>


<script>
    (function () {
        var tab = new fz.Scroll('.ui-tab', {
            role: 'tab',
            autoplay: false,
            interval: 3000
        });
        /* 滑动开始前 */
        tab.on('beforeScrollStart', function (fromIndex, toIndex) {
            console.log(fromIndex, toIndex); // from 为当前页，to 为下一页
        })
    });
    $("#gsubmitbtn").click(function(){
        submitForm();
    });

    $("#register").click(function () {
        window.location.href = "<c:url value='/weixin/wx_member/register_protocol?gowhere=${gowhere}&openId=${openId}'/>";
    });

    function onlyNumber(){
        if ((event.keyCode <48) || (event.keyCode> 57 )) event.returnValue = false;
    }

    function submitForm() {
        var checkInput = true;
        var url = "<c:url value='/api/profile/wx_login'/>";
        //第一页
        if ($("#loginId").val() == "" || $("#password").val() == "") {
            alert("请输入用户名或密码！");
            checkInput = false;
        }
        else if($("#loginId").val().length!=11){
            alert("请输入11位手机号!");
            checkInput = false;
        }
        else if($("#password").val().length < 6 || $("#password").val().length > 20){
            alert("请输入6-20位密码");
            checkInput = false;
        }
        var str ='{"loginId":"' + $("#loginId").val() + '","password":"' + $("#password").val()+ '","openId":"' + $("#openId").val() + '","userSrc":"WEI"}';
        if (checkInput) {
            $.ajax({
                url: url,
                dataType: "json",
                data: str,
                type: "post",
                contentType: "application/json;charset=utf-8",
                success: function (resp, status, xhr) {
                    if (resp.succ) {
                        if (212001 == resp.statusCode) {
                            if ("${gowhere}" == "") {
                                gowhere = "<c:url value='/weixin/wx_member/index'/>";
                            } else {
                                gowhere = "<c:url value='${gowhere}'/>";
                            }
//                            alert(gowhere);
                            window.location.href = gowhere;
                        } else if (2001 == resp.code) {
                            alert("2001！");
                        } else {
                            alert(resp.msg);
                        }
                    } else {
                        alert(resp.msg);
                    }
                }
            });
        }

    }
</script>
</body>

</html>
</html>
